do {
linecount++;
- memset(&buff, '\0', sizeof(buff));
+ memset(buff, '\0', sizeof(buff));
fgets(buff, sizeof(buff), file_in);
if (strlen(buff)) {
* data in this file.
*/
-typedef struct {
- int synthesize_shortnames;
- int debug_level;
-} global_options;
-
-extern global_options global_opts;
/*
* A coordinate in space.
altitude altitude;
} position;
+
+/*
+ * Define globally on which kind of data gpsbabel is working.
+ * Important for "file types" that are essentially a communication
+ * protocol for a receiver, like the Magellan serial data.
+ */
+typedef enum {
+ trkdata = 0 ,
+ wptdata,
+ rtedata
+} gpsdata_type;
+
+typedef struct {
+ int synthesize_shortnames;
+ int debug_level;
+ gpsdata_type objective;
+} global_options;
+
+extern global_options global_opts;
+
+
/*
* Extended data if waypoint happens to represent a geocache. This is
* totally voluntary data...
do {
linecount++;
- memset(&buff, '\0', sizeof(buff));
+ memset(buff, '\0', sizeof(buff));
fgets(buff, sizeof(buff), file_in);
if (strlen(buff)) {
while (s) {
switch (i) {
- case 0: // WPT #, skip.
+ case 0: /* WPT #, skip. */
break;
case 1:
wpt_tmp->position.latitude.degrees = atof(s);
int iWptNum;
int iWptIndex;
WPT *pWptHxTmp;
- int iWptLen;
- DWORD dwIndex;
struct tm tm;
struct tm *ptm;
fatal("GPSBABEL: Error reading data from .wpo file\n");
}
- iWptLen = sizeof(WPT);
iWptNum = le_read16(&((WPTHDR *)HxWpt)->num);
/* Get the waypoints */
wpt_tmp = xcalloc(sizeof(*wpt_tmp), 1);
iWptIndex = le_read16(&((WPTHDR *)HxWpt)->idx[iCount]);
- dwIndex= OFFS_WPT + (sizeof(WPT) * iWptIndex);
pWptHxTmp = (WPT *)&HxWpt[OFFS_WPT + (sizeof(WPT) * iWptIndex)];
wpt_tmp->position.altitude.altitude_meters = 0;
/* set Waypoint */
pWptHxTmp = (WPT *)&HxWFile[OFFS_WPT + (sizeof(WPT) * sIndex)];
- memset (&(pWptHxTmp->name),0x20,sizeof(pWptHxTmp->name));
+ memset (pWptHxTmp->name,0x20,sizeof(pWptHxTmp->name));
if (wpt->shortname != NULL)
- strncpy((char *)&(pWptHxTmp->name), mknshort(wpt->shortname,sizeof(pWptHxTmp->name)),sizeof(pWptHxTmp->name));
+ strncpy(pWptHxTmp->name, mknshort(wpt->shortname,sizeof(pWptHxTmp->name)),sizeof(pWptHxTmp->name));
else
- sprintf((char *)&(pWptHxTmp->name),"W%d",sIndex);
+ sprintf(pWptHxTmp->name,"W%d",sIndex);
- memset (&(pWptHxTmp->comment),0x20,sizeof(pWptHxTmp->comment));
+ memset (pWptHxTmp->comment,0x20,sizeof(pWptHxTmp->comment));
if (wpt->description != NULL)
- strncpy((char *)&(pWptHxTmp->comment), mknshort(wpt->description,sizeof(pWptHxTmp->comment)),sizeof(pWptHxTmp->comment));
+ strncpy(pWptHxTmp->comment, mknshort(wpt->description,sizeof(pWptHxTmp->comment)),sizeof(pWptHxTmp->comment));
/*set the time */
if (wpt->creation_time)
const char * mag_find_descr_from_token(const char *token);
const char * mag_find_token_from_descr(const char *icon);
+
+waypoint * mag_trkparse(char *trkmsg);
#define debug_serial (global_opts.debug_level > 1)
+extern gpsdata_type objective;
+
static char * termread(char *ibuf, int size);
static void termwrite(char *obuf, int size);
isump = &ibuf[isz-1];
isum = strtoul(isump, NULL,16);
if (isum != mag_pchecksum(&ibuf[1], isz-3)) {
-if (debug_serial)
- fprintf(stderr, "RXERR %02x/%02x: '%s'\n", isum, mag_pchecksum(&ibuf[1],isz-5), ibuf);
- /* Special case receive errors early on. */
+ if (debug_serial)
+ fprintf(stderr, "RXERR %02x/%02x: '%s'\n", isum, mag_pchecksum(&ibuf[1],isz-5), ibuf);
+ /* Special case receive errors early on. */
if (!got_version) {
fatal(MYNAME ": bad communication. Check bit rate.\n");
}
waypoint *wpt = mag_wptparse(ibuf);
waypt_add(wpt);
}
+ if (strncmp(ibuf, "$PMGNTRK,", 7) == 0) {
+ waypoint *wpt = mag_trkparse(ibuf);
+ waypt_add(wpt);
+ }
if (IS_TKN("$PMGNVER,")) {
mag_verparse(ibuf);
return;
fclose(magfile_in);
magfile_in = NULL;
}
-#if 0
+
+
/*
* Given an incoming track messages of the form:
* $PMGNTRK,3605.259,N,08644.389,W,00151,M,201444.61,A,,020302*66
sscanf(trkmsg,"$PMGNTRK,%lf,%c,%lf,%c,%d,%c,%d.%d,A,,%d",
&latdeg,&latdir,
- &lngdeg,&lngsecs,&lngdir,
+ &lngdeg,&lngdir,
&alt,&altunits,&hms,&fracsecs,&dmy);
tm.tm_sec = hms % 100;
return waypt;
}
-#endif
+
+
const char *
mag_find_descr_from_token(const char *token)
}
static void
-mag_readwpt(void)
+mag_read(void)
{
if (!is_file) {
- mag_writemsg("PMGNCMD,WAYPOINT");
+ switch (global_opts.objective)
+ {
+ case trkdata:
+ mag_writemsg("PMGNCMD,TRACK,2");
+ break;
+ case wptdata:
+ mag_writemsg("PMGNCMD,WAYPOINT");
+ break;
+ default:
+ fatal(MYNAME ": Routes are not yet supported\n");
+ }
}
- while (!found_done) {
+ while (!found_done)
mag_readmsg();
- }
}
static
mag_wr_init,
mag_deinit,
mag_deinit,
- mag_readwpt,
+ mag_read,
mag_write,
};
global_options global_opts;
+gpsdata_type objective = wptdata; /* if no explicit data type is given, assume waypoints */
+
+
+
void
usage(const char *pname)
{
- printf("Usage: %s [-s] -i <INPUT_FILE_TYPE> -f <INPUT_FILE> -o <OUT FTYPE> -F <OUTPUT_FILE>\n", pname);
+ printf("Usage: %s [-s] [-t|-w|-r] -i <INPUT_FILE_TYPE> -f <INPUT_FILE> -o <OUT FTYPE> -F <OUTPUT_FILE>\n", pname);
printf("Supported file types:\n");
disp_vecs();
}
case 's':
global_opts.synthesize_shortnames = 1;
break;
+ case 't':
+ objective = trkdata;
+ break;
+ case 'w':
+ objective = wptdata;
+ break;
+ case 'r':
+ objective = rtedata;
+ break;
case 'D':
global_opts.debug_level = atoi(optarg);
argn++;
do {
linecount++;
- memset(&buff, '\0', sizeof(buff));
+ memset(buff, '\0', sizeof(buff));
fgets(buff, sizeof(buff), file_in);
if (strlen(buff)) {
do {
linecount++;
- memset(&buff, '\0', sizeof(buff));
+ memset(buff, '\0', sizeof(buff));
fgets(buff, sizeof(buff), file_in);
if ((strlen(buff)) && (strstr(buff, ",") != NULL)) {
lon = (wpt->position.longitude.degrees * M_PI) / 180.0;
/* 4 leading bytes */
- memset(&tbuf, '\0', sizeof(tbuf));
- fwrite(&tbuf, 1, 4, psp_file_out);
+ memset(tbuf, '\0', sizeof(tbuf));
+ fwrite(tbuf, 1, 4, psp_file_out);
/* my test files seem to always have this byte as 0x03, */
/* although nothing seems to really care. */
c = 0x14; /* display pin name on! display notes on! */
fwrite(&c, 1, 1, psp_file_out);
- memset(&tbuf, '\0', sizeof(tbuf));
+ memset(tbuf, '\0', sizeof(tbuf));
/* 3 unknown bytes */
- fwrite(&tbuf, 1, 3, psp_file_out);
+ fwrite(tbuf, 1, 3, psp_file_out);
/* 1 icon byte 0x00 = PIN */
- fwrite(&tbuf, 1, 1, psp_file_out);
+ fwrite(tbuf, 1, 1, psp_file_out);
/* 3 unknown bytes */
- fwrite(&tbuf, 1, 3, psp_file_out); /* 3 junk */
+ fwrite(tbuf, 1, 3, psp_file_out); /* 3 junk */
c = strlen(shortname);
/* 1 string size */
/* insert waypoint count into header */
le_write16(&header_bytes[12], s);
- fwrite(&header_bytes, 1, 32, psp_file_out);
+ fwrite(header_bytes, 1, 32, psp_file_out);
waypt_disp_all(psp_waypt_pr);
}
fwrite(&elev, 1, 2, tpg_file_out);
/* 4 unknown bytes */
- memset(&tbuf, '\0', sizeof(tbuf));
- fwrite(&unknown4, 1, 4, tpg_file_out);
+ memset(tbuf, '\0', sizeof(tbuf));
+ fwrite(unknown4, 1, 4, tpg_file_out);
/* 1 bytes stringsize for description */
c = strlen(description);
fwrite(description, 1, c, tpg_file_out);
/* and finally 2 unknown bytes */
- fwrite(&unknown2, 1, 2, tpg_file_out);
+ fwrite(unknown2, 1, 2, tpg_file_out);
free (shortname);
free (description);
fatal(MYNAME ": attempt to output too many points (%d). The max is %d. Sorry.\n", s, MAXTPGOUTPUTPINS);
}
- le_write16(&uc, s);
+ le_write16(uc, s);
/* write the waypoint count */
- fwrite(&uc, 1, 2, tpg_file_out);
+ fwrite(uc, 1, 2, tpg_file_out);
/* write the rest of the header */
- fwrite(&header_bytes, 1, 19, tpg_file_out);
+ fwrite(header_bytes, 1, 19, tpg_file_out);
waypt_disp_all(tpg_waypt_pr);
}